/*
 *@本JS功能：生成试题详情
 *@本JS作者：杨锡君
 *@编写时间：2017年11月21日
 */
$(function() {
    var Alert1 = new Alert();
    var confirm1 = new Confirm();
    var loading1 = new Loading();
    loading1.init();
    var $courseName = $("#courseName");
    var $saveBtn = $(".saveBtn");
    var $preview = $(".previewBtn");
    var $examTime = $("#examTime"); //考试时间
    var $examName = $("#examName"); //试卷名称
    var $choseNum = $("#choseNum"); //选择数量
    var $choseScore = $("#choseScore"); //选择分数
    var $muchNum = $("#muchNum"); //选择数量
    var $muchScore = $("#muchScore"); //选择分数
    var $gapfillNum = $("#gapfillNum"); //填空数量
    var $gapfillScore = $("#gapfillScore"); //填空分数
    var $checkNum = $("#checkNum"); //判断数量
    var $checkScore = $("#checkScore"); //判断分数
    var $shortNum = $("#shortNum"); //简答数量
    var $shortScore = $("#shortScore"); //简答分数
    var $totalPoint = $(".totalPoint"); //总分数
    var $popup_content = $(".popup_content");
    function choseModel(num,opt,obj){
        var tn = "";
        if(num == 1) {
            tn = "一、";
        } else if(num == 2) {
            tn = "二、";
        } else if(num == 3) {
            tn = "三、";
        }else if(num == 4) {
            tn = "四、";
        } else {
            tn = "五、";
        }
//		选择题模板
        var str = "<h4 class=\"examPageTitle\">"+ tn +"单选题(每题<b class=\"oneChoseScore\">"+ obj.optionSorce +"分</b>，共<b class=\"totalChoseCount\">"+opt.length +"</b>题)</h4>"
        var str1 = "";
        var count = 0;
        $.each(opt, function(key) {
            count++;
            str1 += "<div data-questionid="+ this.questionId +" data-questiontype="+ this.questionType +" class=\"questionBox\">"
                +"<div>"+ count +"."+ this.questionName +"(&emsp;&emsp;)<b style='font-weight: normal;' class=\"trueAnswer\">正确答案："+ this.ansquesContent +"</b></div>"
            $.each(this.optionMsg.split("#"), function(omg) {
                str1 += "<div class=\"choseOne\">"+ this +"</div>"
            });
            str1 +="</div>";
        });

        return str + str1;
    }
    function muchModel(num,opt,obj){
        var tn = "";
        if(num == 1) {
            tn = "一、";
        } else if(num == 2) {
            tn = "二、";
        } else if(num == 3) {
            tn = "三、";
        }else if(num == 4) {
            tn = "四、";
        } else {
            tn = "五、";
        }
//		选择题模板
        var str = "<h4 class=\"examPageTitle\">"+ tn +"多选题(每题<b class=\"oneMuchScore\">"+ obj.manyOptionSorce +"分</b>，共<b class=\"totalMuchCount\">"+opt.length +"</b>题)</h4>"
        var str1 = "";
        var count = 0;
        $.each(opt, function(key) {
            count++;
            str1 += "<div data-questionid="+ this.questionId +" data-questiontype="+ this.questionType +" class=\"questionBox\">"
                +"<div>"+ count +"."+ this.questionName +"(&emsp;&emsp;)<b style='font-weight: normal;' class=\"trueAnswer\">正确答案："+ this.ansquesContent +"</b></div>"
            $.each(this.optionMsg.split("#"), function(omg) {
                str1 += "<div class=\"muchOne\">"+ this +"</div>"
            });
            str1 +="</div>";
        });

        return str + str1;
    }
    function fillModel(num,opt,obj){
        var tn = "";
        if(num == 1) {
            tn = "一、";
        } else if(num == 2) {
            tn = "二、";
        } else if(num == 3) {
            tn = "三、";
        } else {
            tn = "四、";
        }
//		填空题模板
        var str = "<h4 class=\"examPageTitle\">"+ tn +"填空题(每题<b class=\"oneFillScore\">"+ obj.blanksSource +"分</b>，共<b class=\"totalFillCount\">"+ opt.length +"</b>题)</h4>";
        var str1 = "";
        var count = 0;
        $.each(opt, function(key) {
            count++;
            str1 += "<div data-questionid="+ this.questionId +" data-questiontype="+ this.questionType +"  class=\"questionBox\">"
                +"<div class=\"fillAdd\"><b class=\"fillSpace\">"+ count +"."+ this.questionName +"</b><div class=\"trueAnswer\">正确答案："+ this.ansquesContent +"</div></div>"
                +"</div>";
        });

        return str + str1;
    }
    function checkModel(num,opt,obj){
        var tn = "";
        if(num == 1) {
            tn = "一、";
        } else if(num == 2) {
            tn = "二、";
        } else if(num == 3) {
            tn = "三、";
        } else {
            tn = "四、";
        }
        var str = "<h4 class=\"examPageTitle\">"+ tn +"判断题(每题<b class=\"oneCheckScore\">"+ obj.judgeSource +"分</b>，共<b class=\"totalCheckCount\">"+ opt.length +"</b>题,请输入答案T/F)</h4>";
        var str1 = "";
        var count = 0;
        $.each(opt, function(key) {
            count++;
            str1 += "<div data-questionid="+ this.questionId +" data-questiontype="+ this.questionType +"   class=\"questionBox\">"
                +"<div>"+ count +"."+ this.questionName +"(&emsp;&emsp;)<b style='font-weight: normal;' class=\"trueAnswer\">正确答案："+ this.ansquesContent +"</b></div>"
                +"</div>";
        });
        return str + str1;

    }
    function shortModel(num,opt,obj){
        var tn = "";
        if(num == 1) {
            tn = "一、";
        } else if(num == 2) {
            tn = "二、";
        } else if(num == 3) {
            tn = "三、";
        } else {
            tn = "四、";
        }
        var str = "<h4  class=\"examPageTitle\">"+ tn +"简答题(每题<b class=\"oneShortScore\">"+ obj.answerSource +"分</b>，共<b class=\"totalShortCount\">"+opt.length+"</b>题)</h4>";

        var str1 = "";
        var count = 0;
        $.each(opt, function(key) {
            count++;
            str1 += "<div data-questionid="+ this.questionId +" data-questiontype="+ this.questionType +" class=\"questionBox\">"
                +"<div>"+ count +"."+ this.questionName +"<div style='font-weight: normal;' class=\"trueAnswer\">正确答案："+ this.ansquesContent +"</div></div>"
                +"<div class=\"choseOne\"><textarea class=\"shortAnswer answerInt\"></textarea></div>"
                +"</div>";
        });
        return str + str1;

    }
    var testGenerateDetail = {
        init: function() {
            this.bindEvent();
        },
        bindEvent: function() {
            var self = this;
            $courseName.html(result.paramData.courseName);
            $courseName.attr("title",result.paramData.courseName);
            maxLengthLimit.init("publicText");
            self.verificationEvent();
            self.inputChangeEvent();
            $saveBtn.off("click").click(function() {
                var flag = self.saveVerEvent();
                if(flag){
                    self.saveEvent();
                }
            });
            $preview.off("click").click(function() {
                var flag = self.saveVerEvent();
                if(flag){
                    self.previewEvent();
                }

            });
            $(".looktgs").off("click").click(function () {
                var json = JSON.stringify({
                    "pageName":"testGenerateList",
                    "paramData":{
                        "courseId":result.paramData.courseId,
                        "courseName":result.paramData.courseName,
                        "courseTitle":result.paramData.courseTitle
                    }
                });
                window.location.href ="skipPage?jsonStr="+json;
            });
        },
        saveEvent:function(){
//			保存
            var self = this;
            var optionPageSize = $choseNum.val();
            var optionSorce = $choseScore.val();
            if(optionPageSize == ""){
                optionPageSize = 0;
            }else{
                if(optionSorce == ""){
                    Alert1.content = "请输入单选题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(optionPageSize == 0 || optionSorce ==0){
                    Alert1.content = "单选题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            if(optionSorce == ""){
                optionSorce = 0;
            }else{
                if(optionPageSize == ""){
                    Alert1.content = "请输入单选题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(optionPageSize == 0 || optionSorce ==0){
                    Alert1.content = "单选题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            var muchPageSize = $muchNum.val();
            var muchSorce = $muchScore.val();
            if(muchPageSize == ""){
                muchPageSize = 0;
            }else{
                if(muchSorce == ""){
                    Alert1.content = "请输入多选题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(muchPageSize == 0 || muchSorce ==0){
                    Alert1.content = "多选题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            if(muchSorce == ""){
                muchSorce = 0;
            }else{
                if(muchPageSize == ""){
                    Alert1.content = "请输入多选题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(muchPageSize == 0 || muchSorce ==0){
                    Alert1.content = "多选题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            var judgePSize = $checkNum.val();
            var judgeSource = $checkScore.val();
            if(judgePSize == ""){
                judgePSize = 0;
            }else{
                if(judgeSource == ""){
                    Alert1.content = "请输入判断题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(judgePSize == 0 || judgeSource ==0){
                    Alert1.content = "判断题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }

            if(judgeSource == ""){
                judgeSource = 0;
            }else{
                if(judgePSize == ""){
                    Alert1.content = "请输入判断题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(judgePSize == 0 || judgeSource ==0){
                    Alert1.content = "判断题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            var blanksPageSize = $gapfillNum.val();
            var blanksSource = $gapfillScore.val();
            if(blanksPageSize == ""){
                blanksPageSize = 0;
            }else{
                if(blanksSource == ""){
                    Alert1.content = "请输入填空题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(blanksPageSize == 0 || blanksSource ==0){
                    Alert1.content = "填空题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            if(blanksSource == ""){
                blanksSource = 0;
            }else{
                if(blanksPageSize == ""){
                    Alert1.content = "请输入填空题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(blanksPageSize == 0 || blanksSource ==0){
                    Alert1.content = "填空题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            var answerPageSize = $shortNum.val();
            var answerSource = $shortScore.val();
            if(answerPageSize == ""){
                answerPageSize = 0;
            }else{
                if(answerSource == ""){
                    Alert1.content = "请输入简答题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(answerSource == 0 || answerPageSize ==0){
                    Alert1.content = "简答题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }

            if(answerSource == ""){
                answerSource = 0;
            }else{
                if(answerPageSize == ""){
                    Alert1.content = "请输入简答题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(answerSource == 0 || answerPageSize ==0){
                    Alert1.content = "简答题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            var jsonStr = {
                "answerPageNow":0,
                "answerPageSize":Number(answerPageSize),
                "answerSource":Number(answerSource),
                "blanksPageNow":0,
                "blanksPageSize":Number(blanksPageSize),
                "blanksSource":Number(blanksSource),
                "judgePageNow":0,
                "judgePSize":Number(judgePSize),
                "judgeSource":Number(judgeSource),
                "optionPageNow":0,
                "optionPageSize":Number(optionPageSize),
                "optionSorce":Number(optionSorce),
                "manyOptionPageNow":0,
                "manyOptionPageSize":Number(muchPageSize),
                "manyOptionSorce":Number(muchSorce),
                "courseId":result.paramData.courseId
            };
            var obj = {
                "answerPageSize":Number(answerPageSize),
                "blanksPageSize":Number(blanksPageSize),
                "judgePSize":Number(judgePSize),
                "optionPageSize":Number(optionPageSize),
                "manyOptionPageSize":Number(muchPageSize),
            };
            if(Number(answerPageSize) == 0&&Number(answerSource) == 0&&Number(blanksPageSize) == 0&&Number(blanksSource) == 0&&Number(judgePSize) == 0&&Number(judgeSource) == 0&&Number(optionPageSize) == 0&&Number(optionSorce) == 0&&Number(muchPageSize) == 0&&Number(muchSorce) == 0){
                Alert1.content = "请输入至少一种试题类型";
                Alert1.success = function () {
                    $(".mb,.popup").hide();
                };
                Alert1.init();
                Alert1.show();
                return false;
            }
            var json = JSON.stringify(jsonStr);
            $.ajax({
                type:"post",
                url:"getQuestionsByExcel",
                async:true,
                data:{
                    "jsonStr":json
                },
                success:function(msg){
                    msg = JSON.parse(msg);
                    var onlineSumSource = Number($("#muchScore").val()*msg.manyOptionList.length) + Number($("#choseScore").val()*msg.optionList.length) + Number($("#gapfillScore").val()*msg.blanksList.length) + Number($("#checkScore").val()*msg.judgeList.length) + Number($("#shortScore").val()*msg.answerList.length);
                    var meg = msg.errMsg;
                    if(meg!=""){
                        confirm1.content = "<p style='font-size: 16px;'>"+meg+"</p><p style='font-size: 16px;'>当前试卷总分为<span style='color: #C80211;'>"+onlineSumSource+"分</span></p>";
                        confirm1.success = function () {
                            if(msg.mark == 1){
                                Alert1.content = "当前试卷没有试题";
                                Alert1.success = function () {
                                    $(".mb,.popup").hide();
                                };
                                Alert1.init();
                                Alert1.show();
                                return false;
                            }else{
                                var strings = "";
                                var num = 0;
                                var str = "";
                                var str1 = "";
                                var str2 = "";
                                var str3 = "";
                                var str4 = "";
                                if(msg.optionList.length!=0){
                                    num++;
                                    str = choseModel(num,msg.optionList,jsonStr);
                                }
                                if(msg.manyOptionList.length!=0){
                                    num++;
                                    str4 = muchModel(num,msg.manyOptionList,jsonStr);
                                }
                                if(msg.judgeList.length!=0){
                                    num++;
                                    str1 = checkModel(num,msg.judgeList,jsonStr);
                                }
                                if(msg.blanksList.length!=0){
                                    num++;
                                    str2 = fillModel(num,msg.blanksList,jsonStr);
                                }
                                if(msg.answerList.length!=0){
                                    num++;
                                    str3 = shortModel(num,msg.answerList,jsonStr);
                                }
                                strings = str+str4+str1+str2+str3;
                                obj.answersource = Number(answerSource);
                                obj.blankssource = Number(blanksSource);
                                obj.judgesource = Number(judgeSource);
                                obj.optionsource = Number(optionSorce);
                                obj.manyOptionSorce = Number(muchSorce);

                                jsonStr.answersource = Number(answerSource);
                                jsonStr.blankssource = Number(blanksSource);
                                jsonStr.courseId = result.paramData.courseId;
                                jsonStr.courseName = result.paramData.courseName;
                                jsonStr.examtime = Number($examTime.val());
                                jsonStr.judgesource = Number(judgeSource);
                                jsonStr.optionsource = Number(optionSorce);
                                jsonStr.manyOptionSorce = Number(muchSorce);
                                jsonStr.textjson = escape(strings);
                                jsonStr.onlineSumSource = onlineSumSource;
                                jsonStr.fileName = $("#examName").val();
                                jsonStr.mark = 1;
                                jsonStr.randomMark = 1;
                                obj = JSON.stringify(obj);
                                jsonStr.paperDetail = obj;
                                var json = JSON.stringify(jsonStr);
                                $.ajax({
                                    url:"addOnlineQuestion",
                                    type:"post",
                                    async:true,
                                    data:{
                                        "jsonStr":json
                                    },
                                    success:function(msg){
                                        msg = JSON.parse(msg);
                                        if(msg.result == "success"){
                                            Alert1.content = "生成试卷成功";
                                            Alert1.success = function(){
                                                var json = JSON.stringify({
                                                    "pageName":"testGenerateList",
                                                    "paramData":{
                                                        "courseId":result.paramData.courseId,
                                                        "courseName":result.paramData.courseName,
                                                        "courseTitle":result.paramData.courseTitle
                                                    }
                                                });
                                                window.location.href ="skipPage?jsonStr="+json;
                                            };
                                            Alert1.init();
                                            Alert1.show();
                                            return false;
                                        }else{
                                            Alert1.content = msg.errorMsg;
                                            Alert1.success = function () {
                                                $(".mb,.popup").hide();
                                            };
                                            Alert1.init();
                                            Alert1.show();
                                            return false;
                                        }
                                    }
                                });
                            }

                        };
                        confirm1.init();
                        confirm1.show();
                    }else{
                        var strings = "";
                        var num = 0;
                        var str = "";
                        var str1 = "";
                        var str2 = "";
                        var str3 = "";
                        var str4 = "";
                        if(msg.optionList.length!=0){
                            num++;
                            str = choseModel(num,msg.optionList,jsonStr);
                        }
                        if(msg.manyOptionList.length!=0){
                            num++;
                            str4 = muchModel(num,msg.manyOptionList,jsonStr);
                        }
                        if(msg.judgeList.length!=0){
                            num++;
                            str1 = checkModel(num,msg.judgeList,jsonStr);
                        }
                        if(msg.blanksList.length!=0){
                            num++;
                            str2 = fillModel(num,msg.blanksList,jsonStr);
                        }
                        if(msg.answerList.length!=0){
                            num++;
                            str3 = shortModel(num,msg.answerList,jsonStr);
                        }
                        strings = str+str4+str1+str2+str3;
                        obj.answersource = Number(answerSource);
                        obj.blankssource = Number(blanksSource);
                        obj.judgesource = Number(judgeSource);
                        obj.optionsource = Number(optionSorce);
                        obj.manyOptionSorce = Number(muchSorce);
                        jsonStr.answersource = Number(answerSource);
                        jsonStr.blankssource = Number(blanksSource);
                        jsonStr.courseId = result.paramData.courseId;
                        jsonStr.courseName = result.paramData.courseName;
                        jsonStr.examtime = Number($examTime.val());
                        jsonStr.judgesource = Number(judgeSource);
                        jsonStr.optionsource = Number(optionSorce);
                        jsonStr.manyOptionSorce = Number(muchSorce);
                        jsonStr.textjson = escape(strings);
                        jsonStr.onlineSumSource = onlineSumSource;
                        jsonStr.fileName = $("#examName").val();
                        jsonStr.mark = 1;
                        jsonStr.randomMark = 1;
                        obj = JSON.stringify(obj);
                        jsonStr.paperDetail = obj;
                        var json = JSON.stringify(jsonStr);
                        $.ajax({
                            url:"addOnlineQuestion",
                            type:"post",
                            async:true,
                            data:{
                                "jsonStr":json
                            },
                            success:function(msg){
                                msg = JSON.parse(msg);
                                if(msg.result == "success"){
                                    Alert1.content = "生成试卷成功";
                                    Alert1.success = function(){
                                        var json = JSON.stringify({
                                            "pageName":"testGenerateList",
                                            "paramData":{
                                                "courseId":result.paramData.courseId,
                                                "courseName":result.paramData.courseName,
                                                "courseTitle":result.paramData.courseTitle
                                            }
                                        });
                                        window.location.href ="skipPage?jsonStr="+json;
                                    };
                                    Alert1.init();
                                    Alert1.show();
                                    return false;
                                }else{
                                    Alert1.content = msg.errorMsg;
                                    Alert1.success = function () {
                                        $(".mb,.popup").hide();
                                    };
                                    Alert1.init();
                                    Alert1.show();
                                    return false;
                                }
                            }
                        });
                    }


                }
            });
        },
        previewEvent:function(){
//			预览
            var self = this;

            var optionPageSize = $choseNum.val();
            var optionSorce = $choseScore.val();
            if(optionPageSize == ""){
                optionPageSize = 0;
            }else{
                if(optionSorce == ""){
                    Alert1.content = "请输入单选题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(optionPageSize == 0 || optionSorce ==0){
                    Alert1.content = "单选题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            if(optionSorce == ""){
                optionSorce = 0;
            }else{
                if(optionPageSize == ""){
                    Alert1.content = "请输入单选题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(optionPageSize == 0 || optionSorce ==0){
                    Alert1.content = "单选题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            var muchPageSize = $muchNum.val();
            var muchSorce = $muchScore.val();
            if(muchPageSize == ""){
                muchPageSize = 0;
            }else{
                if(muchSorce == ""){
                    Alert1.content = "请输入多选题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(muchPageSize == 0 || muchSorce ==0){
                    Alert1.content = "多选题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            if(muchSorce == ""){
                muchSorce = 0;
            }else{
                if(muchPageSize == ""){
                    Alert1.content = "请输入多选题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(muchPageSize == 0 || muchSorce ==0){
                    Alert1.content = "多选题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }

            var judgePSize = $checkNum.val();
            var judgeSource = $checkScore.val();
            if(judgePSize == ""){
                judgePSize = 0;
            }else{
                if(judgeSource == ""){
                    Alert1.content = "请输入判断题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(judgePSize == 0 || judgeSource ==0){
                    Alert1.content = "判断题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }

            if(judgeSource == ""){
                judgeSource = 0;
            }else{
                if(judgePSize == ""){
                    Alert1.content = "请输入判断题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(judgePSize == 0 || judgeSource ==0){
                    Alert1.content = "判断题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }
            var blanksPageSize = $gapfillNum.val();
            var blanksSource = $gapfillScore.val();
            if(blanksPageSize == ""){
                blanksPageSize = 0;
            }else{
                if(blanksSource == ""){
                    Alert1.content = "请输入填空题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(blanksPageSize == 0 || blanksSource ==0){
                    Alert1.content = "填空题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                    return false;
                }
            }
            if(blanksSource == ""){
                blanksSource = 0;
            }else{
                if(blanksPageSize == ""){
                    Alert1.content = "请输入填空题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(blanksPageSize == 0 || blanksSource ==0){
                    Alert1.content = "填空题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                    return false;
                }
            }
            var answerPageSize = $shortNum.val();
            var answerSource = $shortScore.val();
            if(answerPageSize == ""){
                answerPageSize = 0;
            }else{
                if(answerSource == ""){
                    Alert1.content = "请输入简答题分数";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(answerSource == 0 || answerPageSize ==0){
                    Alert1.content = "简答题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }

            if(answerSource == ""){
                answerSource = 0;
            }else{
                if(answerPageSize == ""){
                    Alert1.content = "请输入简答题数量";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
                if(answerSource == 0 || answerPageSize ==0){
                    Alert1.content = "简答题分数/数量不能为0";
                    Alert1.success = function () {
                        $(".mb,.popup").hide();
                    };
                    Alert1.init();
                    Alert1.show();
                    return false;
                }
            }

            if(Number(answerPageSize) == 0&&Number(answerSource) == 0&&Number(blanksPageSize) == 0&&Number(blanksSource) == 0&&Number(judgePSize) == 0&&Number(judgeSource) == 0&&Number(optionPageSize) == 0&&Number(optionSorce) == 0&&Number(muchPageSize) == 0&&Number(muchSorce) == 0){
                Alert1.content = "请输入至少一种试题类型";
                Alert1.success = function () {
                    $(".mb,.popup").hide();
                };
                Alert1.init();
                Alert1.show();
                return false;
            }
            var jsonStr = {
                "answerPageNow":0,
                "answerPageSize":Number(answerPageSize),
                "answerSource":Number(answerSource),
                "blanksPageNow":0,
                "blanksPageSize":Number(blanksPageSize),
                "blanksSource":Number(blanksSource),
                "judgePageNow":0,
                "judgePSize":Number(judgePSize),
                "judgeSource":Number(judgeSource),
                "optionPageNow":0,
                "optionPageSize":Number(optionPageSize),
                "optionSorce":Number(optionSorce),
                "manyOptionPageNow":0,
                "manyOptionPageSize":Number(muchPageSize),
                "manyOptionSorce":Number(muchSorce),
                "courseId":result.paramData.courseId
            };
            var json = JSON.stringify(jsonStr);
            $.ajax({
                type:"post",
                url:"getQuestionsByExcel",
                async:true,
                data:{
                    "jsonStr":json
                },
                success:function(msg){
                    msg = JSON.parse(msg);
                    var meg = msg.errMsg;
                    if(meg != ""){
                        Alert1.content = meg;
                        Alert1.success = function () {
                            self.previewShowEvent(msg,jsonStr);
                            $(".downloadExam").off("click").click(function() {
                                // jsonStr.courseId = result.paramData.courseId;
                                jsonStr.type = "word";
                                if(jsonStr.answerPageSize==0&&jsonStr.answerSource==0&&jsonStr.blanksPageSize==0&&jsonStr.blanksSource==0&&jsonStr.judgePSize==0&&jsonStr.judgeSource==0&&jsonStr.optionPageSize==0&&jsonStr.optionSorce==0&&jsonStr.manyOptionPageSize==0&&jsonStr.manyOptionSorce==0){
                                    Alert1.content = "当前没有试题不能下载";
                                    Alert1.init();
                                    Alert1.show();
                                    return false;
                                }else{
                                    jsonStr.fileName = $("#examName").val();
                                    window.location.href="questionWord?jsonStr="+JSON.stringify(jsonStr);
                                }
                            });
                        };
                        Alert1.init();
                        Alert1.show();
                    }else{
                        self.previewShowEvent(msg,jsonStr);
                        $(".downloadExam").off("click").click(function() {
                            // jsonStr.courseId = result.paramData.courseId;
                            jsonStr.type = "word";
                            if(jsonStr.answerPageSize==0&&jsonStr.answerSource==0&&jsonStr.blanksPageSize==0&&jsonStr.blanksSource==0&&jsonStr.judgePSize==0&&jsonStr.judgeSource==0&&jsonStr.optionPageSize==0&&jsonStr.optionSorce==0&&jsonStr.manyOptionPageSize==0&&jsonStr.manyOptionSorce==0){
                                Alert1.content = "当前没有试题不能下载";
                                Alert1.init();
                                Alert1.show();
                                return false;
                            }else{
                                jsonStr.fileName = $("#examName").val();
                                window.location.href="questionWord?jsonStr="+JSON.stringify(jsonStr);
                            }
                        });
                    }


                }
            });
        },
        previewShowEvent:function(opt,obj){
//			预览展示
            $(".mb,.popup").show();
            var num = 0;
            var str = "";
            var str1 = "";
            var str2 = "";
            var str3 = "";
            var str4 = "";
            if(opt.optionList.length!=0){
                num++;
                str = choseModel(num,opt.optionList,obj);
            }
            if(opt.manyOptionList.length!=0){
                num++;
                str4 = muchModel(num,opt.manyOptionList,obj);
            }
            if(opt.judgeList.length!=0){
                num++;
                str1 = checkModel(num,opt.judgeList,obj);
            }
            if(opt.blanksList.length!=0){
                num++;
                str2 = fillModel(num,opt.blanksList,obj);
            }
            if(opt.answerList.length!=0){
                num++;
                str3 = shortModel(num,opt.answerList,obj);
            }
            $popup_content.html(str+str4+str1+str2+str3);
            $.each($(".fillSpace"), function(opt) {
                $(this).html($(this).html().replace(/\(\+\)/g,"(&emsp;&emsp;)"));
            });
            $(".popup_img").off("click").click(function() {
                $(".mb,.popup").hide();
            });
        },
        inputChangeEvent: function() {
            $(".publicText").change(function() {
                var totalChoseScore = 0;
                var totalMuchScore = 0;
                var totalGapfillScore = 0;
                var totalCheckScore = 0;
                var totalShortScore = 0;
                if($choseNum.val() != "" && $choseScore.val() != "") {
                    totalChoseScore = $choseNum.val() * $choseScore.val();
                }
                if($muchNum.val() != "" && $muchScore.val() != "") {
                    totalMuchScore = $muchNum.val() * $muchScore.val();
                }
                if($gapfillNum.val() != "" && $gapfillScore.val() != "") {
                    totalGapfillScore = $gapfillNum.val() * $gapfillScore.val();
                }
                if($checkNum.val() != "" && $checkScore.val() != "") {
                    totalCheckScore = $checkNum.val() * $checkScore.val();
                }
                if($shortNum.val() != "" && $shortScore.val() != "") {
                    totalShortScore = $shortNum.val() * $shortScore.val();
                }
                $totalPoint.html(totalChoseScore + totalMuchScore + totalGapfillScore + totalCheckScore + totalShortScore);
            });
        },
        saveVerEvent: function() {
            //			保存事件
            if($("#examName").val() == "") {
                Alert1.content = "请输入试卷名称";
                Alert1.success = function () {
                    $(".mb,.popup").hide();
                };
                Alert1.init();
                Alert1.show();
                return false;
            }
            if($examTime.val() == "") {
                Alert1.content = "请输入考试时间";
                Alert1.success = function () {
                    $(".mb,.popup").hide();
                };
                Alert1.init();
                Alert1.show();
                return false;
            }
            if($examTime.val() == 0) {
                Alert1.content = "考试时间不能为0";
                Alert1.success = function () {
                    $(".mb,.popup").hide();
                };
                Alert1.init();
                Alert1.show();
                return false;
            }
            return true;
//			if($choseNum.val() == "" && $choseScore.val() == ""||$gapfillNum.val() == "" && $gapfillScore.val() == ""&&$checkNum.val() == "" && $checkScore.val() == ""&&$shortNum.val() == "" && $shortScore.val() == ""){
//				Alert1.content = "请至少输入一项试卷题型";
//				Alert1.init();
//				Alert1.show();
//				return false;
//			}

        },
        verificationEvent: function() {
            //			输入框校验
            $(".publicText").off("blur").blur(function() {
                if($(this).val() != "") {
                    var flag = verification.numberCode($(this).val());
                    var flags = verification.spaceCode($(this).val());
                    if(flag != true) {
                        Alert1.content = $(this).siblings("label").html() + flag;
                        Alert1.success = function () {
                            $(".mb,.popup").hide();
                        };
                        $(this).val("");
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                    if(flags != true) {
                        Alert1.content = $(this).siblings("label").html() + flags;
                        Alert1.success = function () {
                            $(".mb,.popup").hide();
                        };
                        $(this).val("");
                        Alert1.init();
                        Alert1.show();
                        return false;
                    }
                }
            });
        }
    };
    testGenerateDetail.init();
});